TCP/IP services. How does the networking system work?
6.2. Q - Where do I start in understanding the source code? (Cont)
6. Task: TaskDist(), in netdist.c, wakes up as a result of the MSG_GOT_PAK_IP
message.
IPGetHeader() is called to find out what kind of IP the packet is from.
7. Since this packet is type ICMP, a message is put in message queue: MSG_ICMP.
8. Task: TaskICMPGetPut(), in icmp.c, wakes up as a result of the MSG_ICMP
message.
A trasmit buffer is reserved in the RTL8019AS memory via the MACGetTxBuffer()
call.
The task reads in the entire packet with all the data.
IPPutHeader() is called to prepare a transmit buffer in the RTL8019AS memory.
IPPutArray() is called to put in additional ICMP data.
MACFlush() is called to send the buffer.
The receive buffer in the RTL8019AS memory is discarded.
9. The RTL8019AS sends the buffer over the Ethernet cable.
A packet that will be processed by a TCP/IP handler (telnet, HTTP, FTP), involves
more complexity but the basic structure will be the same.
Steps 1-6 are the same for all network packet types.
For a much more complex example, let's look at a telnet packet.
Steps 1-6 are the same so we continue from step 7.
7. Since this packet is type TCP, a message is put in message queue:
MSG_GOT_TCP.
8. Task: TaskTCPProcess(), in tcprcv.c, wakes up as a result of the MSG_GOT_TCP
message.
FindPacketBuffer() is called to get the next available TCP packet in the packet
receive queue.
It is possible that multiple MSG_GOT_TCP messages have been pushed in the
message queue, since the task: TaskDist() has a higher priority that us.
We always need to run FindPacketBuffer() in order to get the packets in proper
order.
9. The packet is checksummed and a matching socket is found that is waiting for
data. In this case the socket is bound for the telnet server.
10. If the socket is not open yet, we start the open procedure and send a wakeup call
to the telnet server. The telnet server will initialize itself as a result of the socket
being opened.
11. If the socket is open, the length of the data in the packet is computed and the telnet
client is sent a wake up so the data can be processed.